Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkbox): Support checkbox click action config #8521

Merged
merged 2 commits into from
Dec 1, 2017

Conversation

tinayuangao
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 17, 2017
@@ -23,6 +23,24 @@ While the `indeterminate` property of the checkbox is true, it will render as in
regardless of the `checked` value. Any interaction with the checkbox by a user (i.e., clicking) will
remove the indeterminate state.

### Click action config
When user clicks on the `mat-checkbox`, the default behavior is toggle `checked` value and set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that this matches the behavior of the native <input type="checkbox">?


// Emit our custom change event if the native input emitted one.
// It is important to only emit it, if the native input triggered one, because
// we don't want to trigger a change event, when the `checked` variable changes for example.
this._emitChangeEvent();
} else if (!this.disabled && this._clickAction === 'noop') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be !== 'noop'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the input element's check is set to true, indeterminate set to false on user click. When the setting is noop, we will need to reset it to current mat-checkbox's indeterminate and checked.

testComponent = fixture.debugElement.componentInstance;

inputElement = <HTMLInputElement>checkboxNativeElement.querySelector('input');
labelElement = <HTMLLabelElement>checkboxNativeElement.querySelector('label');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer as HTMLElement (even if the other tests use the other syntax from before we had that rule)

labelElement = <HTMLLabelElement>checkboxNativeElement.querySelector('label');
});

it('should not set indeterminate to false on click if noop is set', fakeAsync(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beforeEach provides check, but this test says noop

@@ -542,6 +543,88 @@ describe('MatCheckbox', () => {
expect(checkboxNativeElement).not.toMatch(/^mat\-checkbox\-anim/g);
});
});

describe('click action checked only setting', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe(`when MAT_CHECKBOX_CLICK_ACTION is 'check'`, ...

?

}));
});

describe('click action noop setting', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe(`when MAT_CHECKBOX_CLICK_ACTION is 'noop'`, ...

?

expect(checkboxNativeElement.classList).not.toContain('mat-checkbox-checked');
expect(inputElement.indeterminate).toBe(true);
expect(checkboxNativeElement.classList).toContain('mat-checkbox-indeterminate');
}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for not toggling checked when it is using 'noop'?

@tinayuangao
Copy link
Contributor Author

Comments addressed. Please take a look. Thanks!

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 28, 2017
@tinayuangao tinayuangao merged commit 537b8b5 into angular:master Dec 1, 2017
@tinayuangao tinayuangao deleted the checkbox-indeterminate branch December 1, 2017 19:18
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants